package com.lagou.dao;

import com.lagou.util.JDBCUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import javax.sql.DataSource;
import java.sql.SQLException;

public class LoginDao {
    public static Long login(String name,String pass) throws SQLException {
        //1.获取连接池DataSource对象
        DataSource dataSource = JDBCUtils.getDataSource();

        //2.使用DBUtils
        QueryRunner qr = new QueryRunner(dataSource);

        //3.查询操作
        Object[] params = new String[2];
        params[0] = name;
        params[1] = pass;
        Long count = (Long) qr.query("select count(*) from user where loginname = ? and password=?", new ScalarHandler(),params );
        return count;
    }
}
